<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/23 0023
 * Time: 下午 2:06
 */

namespace App\Http\Admin\Customer\Controllers;

use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Eloquent\Ygt\CustomerAddress;
use App\Eloquent\Province;
use App\Eloquent\City;
use App\Eloquent\Area;

class AddressController extends Controller
{
    protected $modelName = 'CustomerAddress';
    protected $company = true;

    protected $rules = [
//        'customer_name' => 'bail|required',
//        'sort_id' => 'required',
    ];

    public function __construct()
    {
        parent::__construct();
        $this->model = new CustomerAddress();

    }

    protected function _cdata(){
        $provinceInfo = Province::where('provinceID',request('province_id'))->first();
        $cityInfo = City::where('cityID',request('city_id'))->first();
        $areaInfo = Area::where('areaID',request('area_id'))->first();
        $cdata = [
            'province_name' => isset($provinceInfo->province)?$provinceInfo->province:'',
            'city_name' => isset($cityInfo->city)?$cityInfo->city:'',
            'area_name' => isset($areaInfo->area)?$areaInfo->area:'',
            'customer_id'=>request('customer_id')
        ];
        return $cdata;
    }

    protected function _hdata($result){
        $result->transform(function ($item, $key) {
            $item->customer_name = isset($item->customer['customer_name'])?$item->customer['customer_name']:'';
            return $item;
        });
        return $result;
    }
    protected function _honedata($info){
        $info->customer_name = isset($info->customer->customer_name)?$info->customer->customer_name:'';
        return $info;
    }

    protected function _vdataAdd(){
        $provinceList           = Province::all();

        $customerId = request('customer_id');
        return compact('customerId','provinceList');
    }

    protected function _where()
    {
        return [
            'customer_id'=>request('customer_id')
        ];
    }
    protected function _vdata()
    {
        $customerId = request('customer_id');

        return compact('customerId');
    }
}